package users

import (
	"api/internal/respons"
	"context"
	"user_srv/userclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type MembershipLevelUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewMembershipLevelUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MembershipLevelUpdateLogic {
	return &MembershipLevelUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *MembershipLevelUpdateLogic) MembershipLevelUpdate(req *types.MembershipLevelUpdateRequest) (resp *types.Response, err error) {
	opinions, err := l.svcCtx.UserRpc.MembershipLevelUpdate(l.ctx, &userclient.MembershipLevelUpdateRequest{
		Id:          req.Id,
		Name:        req.Name,
		Grade:       req.Grade,
		Description: req.Description,
	})
	if err != nil {
		return respons.Error(400, "会员等级更新失败", err.Error()), err
	}
	return respons.Success(opinions), nil
}
